//
//  WMETheFindTableViewCell.m
//  everyDay_duiTang
//
//  Created by 恩叔 on 16/2/1.
//  Copyright © 2016年 enshu. All rights reserved.
//

#import "WMETheFindTableViewCell.h"
#import <Masonry.h>


@interface WMETheFindTableViewCell ()
@property (nonatomic, retain)UILabel *leftTilte;/**<标题*/
@property (nonatomic, retain)UILabel *line;/**<线*/
@property (nonatomic, retain)UIButton *btn1;/**<左上按钮*/
@property (nonatomic, retain)UIButton *btn2;/**<右上按钮*/
@property (nonatomic, retain)UIButton *btn3;/**<左下按钮*/
@property (nonatomic, retain)UIButton *btn4;/**<右下按钮*/


@end

@implementation WMETheFindTableViewCell
- (void)dealloc
{
    [_leftTilte release];
    [_line release];
    [_btn1 release];
    [_btn2 release];
    [_btn3 release];
    [_btn4 release];
    [super dealloc];
}
- (void)setDataArr:(NSMutableArray *)dataArr
{
    if (_dataArr != dataArr) {
        [_dataArr release];
        _dataArr = [dataArr retain];
        [_btn1 setTitle:_dataArr[0][@"name"] forState:UIControlStateNormal];
//        NSLog(@"~!~!~!~!~~!~!%@", _dataArr[0][@"name"]);
        
        [_btn2 setTitle:_dataArr[1][@"name"] forState:UIControlStateNormal];
        [_btn3 setTitle:_dataArr[2][@"name"] forState:UIControlStateNormal];
        [_btn4 setTitle:_dataArr[3][@"name"] forState:UIControlStateNormal];
    }
}
- (void)setTitleStr:(NSString *)titleStr
{
    if (_titleStr != titleStr) {
        [_titleStr release];
        _titleStr = [titleStr retain];
        _leftTilte.text = _titleStr;
    }
}
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        //初始化 左上角的标题
        self.leftTilte = [[UILabel alloc] init];
        _leftTilte.backgroundColor = [UIColor lightGrayColor];
        _leftTilte.font = [UIFont systemFontOfSize:13];
        _leftTilte.layer.cornerRadius = 10;
        _leftTilte.clipsToBounds = YES;
        _leftTilte.textAlignment = NSTextAlignmentCenter;
        [self.contentView addSubview:_leftTilte];
        [_leftTilte release];
        //初始化 用来分割 标题和内容的线
        self.line = [[UILabel alloc] init];
        _line.backgroundColor = [UIColor orangeColor];
        [self.contentView addSubview:_line];
        [_line release];
        //按钮1 (左上)
        self.btn1 = [UIButton buttonWithType:UIButtonTypeSystem];
        [_btn1 addTarget:self action:@selector(btn1Action:) forControlEvents:UIControlEventTouchUpInside];
        [_btn1 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
//        _btn1.backgroundColor = [UIColor redColor];
        _btn1.tag = 4000;
        [self.contentView addSubview:_btn1];
        //按钮2 (右上)
        self.btn2 = [UIButton buttonWithType:UIButtonTypeSystem];
        [_btn2 addTarget:self action:@selector(btn2Action:) forControlEvents:UIControlEventTouchUpInside];
        [_btn2 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
//        _btn2.backgroundColor = [UIColor yellowColor];
        _btn2.tag = 4001;
        [self.contentView addSubview:_btn2];
        //按钮3 (左下)
        self.btn3 = [UIButton buttonWithType:UIButtonTypeSystem];
        [_btn3 addTarget:self action:@selector(btn3Action:) forControlEvents:UIControlEventTouchUpInside];
        [_btn3 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
//        _btn3.backgroundColor = [UIColor orangeColor];
        _btn3.tag = 4002;
        [self.contentView addSubview:_btn3];
        //按钮4 (右下)
        self.btn4 = [UIButton buttonWithType:UIButtonTypeSystem];
        [_btn4 addTarget:self action:@selector(btn4Action:) forControlEvents:UIControlEventTouchUpInside];
        [_btn4 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        _btn4.tag = 4003;
//        _btn4.backgroundColor = [UIColor blueColor];
        [self.contentView addSubview:_btn4];
    }
    return self;
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    
    __block __typeof(&*self)ws = self;
    
    //设置左上角label的大小和自适应
    [_leftTilte mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(76, 20));
        
        make.top.equalTo(ws.mas_top).with.offset(0);
        make.left.equalTo(ws.mas_left).with.offset(10);
    }];
    
    //设置分割线 大小 自适应
    [_line mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(self.contentView.bounds.size.width - 80, 1));
        
        make.left.equalTo(_leftTilte.mas_right).with.offset(2);
        make.top.equalTo(ws.mas_top).with.offset(9.5);
        make.right.equalTo(ws.mas_right).with.offset(0);
    }];
    
    //按钮1 的位置 (左上)
    [_btn1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(100, 40));
        make.left.equalTo(ws.mas_left).with.offset(50);
        make.top.equalTo(_line.mas_bottom).with.offset(20);
    }];
    
    //按钮2 的位置 (右上)
    [_btn2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(100, 40));
        make.right.equalTo(ws.mas_right).with.offset(-50);
        make.top.equalTo(_line.mas_bottom).with.offset(20);
    }];
    
    //按钮3 的位置 (左下)
    [_btn3 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(100, 40));
        make.left.equalTo(ws.mas_left).with.offset(50);
        make.bottom.equalTo(ws.mas_bottom).with.offset(-10);
    }];
    
    [_btn4 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(100, 40));
        make.right.equalTo(ws.mas_right).with.offset(-50);
        make.bottom.equalTo(ws.mas_bottom).with.offset(-10);
    }];
    
}

#pragma mark - btn1的点击方法
- (void)btn1Action:(UIButton *)btn
{
    NSString *target = _dataArr[0][@"target"];
    NSLog(@"%@", target);
    [self.delegate findPushAction:target];
}

#pragma mark - btn2的点击方法
- (void)btn2Action:(UIButton *)btn
{
    NSString *target = _dataArr[1][@"target"];
    NSLog(@"%@", target);
    [self.delegate findPushAction:target];
}

#pragma mark - btn3的点击方法
- (void)btn3Action:(UIButton *)btn
{
    NSString *target = _dataArr[2][@"target"];
    [self.delegate findPushAction:target];
}

#pragma mark - btn4的点击方法
- (void)btn4Action:(UIButton *)btn
{
    NSString *target = _dataArr[3][@"target"];
    [self.delegate findPushAction:target];
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
